package com.andnnl.date;

import javax.sound.midi.Soundbank;
import java.util.Arrays;
import java.util.Calendar;

/**
 * Created by chenss on 2020/3/9.
 */
public class DateTest {
    public static byte[] toByteArray(String hexString) {
        if (hexString == null || "".equals(hexString.trim()))
            throw new IllegalArgumentException("this hexString must not be empty");

        hexString = hexString.toLowerCase().replaceAll(" ", "");
        final byte[] byteArray = new byte[hexString.length() / 2];
        int k = 0;
        for (int i = 0; i < byteArray.length; i++) {//因为是16进制，最多只会占用4位，转换成字节需要两个16进制的字符，高位在先
            byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff);
            byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff);
            byteArray[i] = (byte) (high << 4 | low);
            k += 2;
        }
        return byteArray;
    }

    public static void main(String[] args) {
        Calendar calendar=Calendar.getInstance();
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        String dx = Integer.toHexString(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(dx);
        if(dx.length()==1)
            dx="0"+dx;
        byte[] day=toByteArray(dx);
        System.out.println(Arrays.toString(day));
    }
}
